<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ page import="com.CGFrame.struts.POJOs.Shot" %>
<%@ page import="com.CGFrame.struts.POJOs.Shotgroup" %>
<%@ page import="com.CGFrame.struts.POJOs.Catemodel" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>Relate Model </title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<LINK href="../styles/sciencee.css"  type=text/css rel=stylesheet>
	<script language=javascript>
		function showImg(name){
			var a=document.getElementById("modelImg");
			a.setAttribute("src","<%=request.getContextPath() %>/categorySet/images/"+name+".jpg");
		}
		function showImg(name){
				var a=document.getElementById("modelImg")
				a.setAttribute("src","<%=path %>/categorySet/images/"+name+".jpg");
		}
	function create1(){
  		var radios = document.getElementsByName("rd");
		for(var i=0;i<radios.length;i++){
  			if(radios[i].checked==true){
  				alert(radios[i].nextSibling);
  				alert(radios[i].nextSibling.nextSibling);
  				var id=radios[i].nextSibling.nextSibling.getAttribute("id");
				setModel(radios[i].value,id);
			}
  		}
	}
	function setModel(cmodel,id){
		var checks=document.getElementsByName("shotCheck");
		if(navigator.appName=="Microsoft Internet Explorer"){
			for(var i=0;i<checks.length;i++){
				if(checks[i].checked==true){
					var a=checks[i].parentNode.nextSibling.nextSibling;
					alert(a);
					a.innerHTML=cmodel;
					var v=checks[i].getAttribute("value");
					var hid=document.getElementById(id);
					hid.value+=v+",";
					alert(hid.value);
				}
			}
  		}else{
  			for(var i=0;i<checks.length;i++){
  				if(checks[i].checked==true){
					var a=checks[i].parentNode.nextSibling.nextSibling.nextSibling.nextSibling;
					alert(a);
					a.innerHTML=cmodel;
					var v=checks[i].getAttribute("value");
					var hid=document.getElementById(id);
					hid.value+=v+",";
					alert(hid.value);
				}
			}
		}
	}
	function submitAll(){
		var shots=document.getElementById("sModel");
		var elements=document.getElementById("eModel");
		var form1=document.getElementById("form1");
		var hidModels=document.getElementsByName("hidModel");
		for(var i=0;i<hidModels.length;i++){
			var a=hidModels[i].getAttribute("id")+":";
			var b=hidModels.value;
			shots.value+=a+b;
		}
		alert(shots.value);
	}
	function changeScene(id){
			var sel=document.getElementById("epSelect").value;
			var vsel=document.getElementById(sel);
			hidSelect();
			vsel.style.display="";
		}
		function hidSelect(){
			var sels=document.getElementsByName("vSel");
			for(var i=0;i<sels.length;i++){
				sels[i].style.display="none";
			}
		}
		
	</script>
  </head>
  
  <body >
    <form id="form1" action="relateModel.do">
    <center><h1><bean:message key="set"/>&nbsp; <bean:messge key="model"/></h1></center>
    <input type="hidden" name="shots" id="sModel">
    <input type="hidden" name="elements" id="eModel">
    <table border="1">
    	<tr>
    		<td><bean:message key="episode"/><select id="epSelect" onchange="changeScene();">
    			<option><bean:message key="selectall"/></option>
<%
	Set epList=(Set)request.getAttribute("epList");
	ArrayList epsList=new ArrayList();
	for(Iterator iter=epList.iterator();iter.hasNext();){
		Shotgroup eps=(Shotgroup)iter.next();
		epsList.add(eps);
%>
				<option value="<%=eps.getShotGroupId() %>"><%=eps.getShotGroupName() %></option>
<%}%>		</select></td>
<td><bean:message key="scene"/>
<%
	for(Iterator iter=epsList.iterator();iter.hasNext();){
		Shotgroup ep=(Shotgroup)iter.next();
%>
	<select id="<%=ep.getShotGroupId()%>" name="vSel" style="display:none" onchange="changeShot();">
	<option><bean:message key="selectall"/></option>
<%
		Set scene=ep.getShotgroups();
		for(Iterator iter1=scene.iterator();iter1.hasNext();){
			Shotgroup sg=(Shotgroup)iter1.next();
%>
			<option ><%=sg.getShotGroupName() %></option>
<%}%>
		</select>
<%} %>

    	</select></td>
    	</tr>
    </table>
    <table >
    <tr><td>
    	<table id="shots" border="1">
    	<tr>
    		<td><input type="checkbox"><bean:message key="selectall"/></td>
    		<td><bean:message key="shot.name"/></td>
    		<td><bean key="modelselected"/></td>
    	</tr>
    	<%
    		LinkedHashSet list1=(LinkedHashSet)request.getAttribute("shotList");
    		for(Iterator iter=list1.iterator();iter.hasNext();){
    			Shot shot=(Shot)iter.next();
    	%>
    	<tr id="<%=shot.getShotId()%>" >
    		<td><input type="checkbox" name="shotCheck" value="<%=shot.getShotId() %>"></td>
    		<td><%=shot.getShotName() %></td>
    		<td></td>
    	</tr>
    	<%} %>
    	</table>

    </td><td>
    	<table border="1">
    	<tr>
    		<td><bean:message key="model"/></td>
    		<td><bean:message key="modelname"/></td>
    		<td><bean:message key="modeltype"/></td>
    		<td><bean:message key="modeldes"/></td>
    	</tr>
    	<%
    		List models=(List)request.getAttribute("shotModels");
    		for(Iterator iter=models.iterator();iter.hasNext();){
    			Catemodel shotModel=(Catemodel)iter.next();
    	%>
    		<tr>
    			<td>
    			<input type="radio" name="rd" value="<%=shotModel.getCateModelName() %>" onclick="showImg('<%=shotModel.getCateModelName() %>');">
				<input type="hidden" id="<%=shotModel.getCateModelId() %>" name="hidModel">
    			</td>
    			<td><%=shotModel.getCateModelName() %></td>
    			<td><%=shotModel.getCateModelType() %></td>
    			<td><%=shotModel.getDescription() %></td>
    		</tr>
    	<%} %>
    	<tr><td><input type="button" value="Create" onclick="create1();"></td></tr>
    	</table>
    </td>
    <td><img id="modelImg" alt="<bean:message key="previewpictureofdirectory"/>"></td>
    </tr>
    </table>
    <input type="button" onclick="submitAll();" value="<bean:message key='submit'/>">
    <input type="reset" value="<bean:message key='reset'/>">
    </form>
  </body>
</html>
